package interview.javabase.classloader;

import com.study.common.ListNode;
import com.study.common.TreeNode;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * @author 大硕
 * 2019-04-06 12:09 PM
 **/
@Slf4j
public class ClassLoaderMain {

    @Test
    public void test() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        Class c = Class.forName("com.study.common.ListNode");
        ListNode ln = (ListNode) c.newInstance();
        ln.val = 123;
        log.info("ln.val:{}", ln.val);

        ClassLoader loader = new ClassLoader() {
            @Override
            public Class<?> loadClass(String name) throws ClassNotFoundException {
                return super.loadClass(name);
            }
        };

        Class tn = loader.loadClass("com.study.common.TreeNode");
        TreeNode tnc = (TreeNode) tn.newInstance();
        log.info("ln.val:{}", tnc.val);
    }
}